#include <vector>
#include <iostream>

using namespace std;

class Solution {
public:
    bool canThreePartsEqualSum(vector<int>& A) {
        int sum = 0;
        for (int item : A) {
            sum += item;
        }
        if (sum % 3 != 0) {
            return false;
        }
        sum = sum / 3;
        int left_i = 0;
        int left_sum = 0;
        for (; left_i < A.size() - 2; left_i++) {
            left_sum += A[left_i];
            if (left_sum == sum) {
                break;
            }
        }
        if (left_sum != sum) {
            return false;
        }
        int right_i = A.size() - 1;
        int right_sum = 0;
        for (; right_i > left_i + 1; right_i--) {
            right_sum += A[right_i];
            if (right_sum == sum) {
                break;
            }
        }
        if (right_sum != sum) {
            return false;
        }
        return true;
    }
};

int main() {
    vector<int> input = {3, 3, 6, 5, -2, 2, 5, 1, -9, 4};
    Solution solution;
    bool output = solution.canThreePartsEqualSum(input);
    cout << output << endl;
    return 0;
}